<%@ Page language="vb" CodeFile="searchClaim.aspx.vb" Inherits="searchClaim_aspx_vb" %>
<%
    
    BRANDID1 = 118
    MODELLID1 = 1462
    
    rowNumber = 1
    flushCounter = 0
    subDo = Request.QueryString("subDo")
    If (Request.QueryString("do")) = Nothing Then 
        claimStatus = Request.QueryString("claimStatus")
        strTop50 = Request.QueryString("strTop50")
        claimStatus = CLng(claimStatus)
        If CInt(claimStatus) = 0 Then 
            strClaimStatus = "NOT PROCESSED"
        ElseIf CInt(claimStatus) = 1 Then 
            strClaimStatus = "UNDER PROCESSING"
        ElseIf CInt(claimStatus) = 2 Then
            strClaimStatus = "PROCESSED"
        ElseIf CInt(claimStatus) = 3 Then 
            strClaimStatus = "SETTLED"
        End IF
        If Len(strTop50) = 0 Then 
            strTop50 = 1
        End IF
        If CInt(strTop50) = 1 Then 
            sqlTop50 = "Top 50"
        Else
            sqlTop50 = ""
        End IF
        If subDo = "print" Then 
            tableWidth = "100%"
            OverPrint()
        Else
            tableWidth = "100%"
            Over()
        End IF
        dbOpen()
        RecSet = Conn.Execute("Select Count(c.claimID) As claimCount From tblClaim c Where c.claimStatus = " & claimStatus & "")
        claimCount = RecSet.Fields("claimCount").Value
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='" & tableWidth & "'>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top' colspan='3'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='" & tableWidth & "'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='12'>")
        Response.Write("SEARCH CLAIM ")
        If CInt(strTop50) = 1 And CInt(claimCount) > 50 Then 
            Response.Write("- LATEST 50")
        End IF
        Response.Write("- " & strClaimStatus & "")
        If CInt(strTop50) = 1 And Len(subDo) = 0 And CInt(claimCount) > 50 Then 
            Response.Write(" <a href='searchClaim.aspx?strTop50=0&claimStatus=" & claimStatus & "'>[SHOW ALL " & claimCount & " CLAIMS]</a>")
        End IF
        If Len(subDo) = 0 Then 
            Response.Write("<a href='searchClaim.aspx?subDo=print&strTop50=" & strTop50 & "&claimStatus=" & claimStatus & "' target='_blank'><img src='gui/printer.gif' align='right' alt='Printable version' border='0'></a>")
        End IF
        Response.Write("<hr class='hrHeadline'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        dbOpen()
          RecSet = Conn.Execute("Select  " & sqlTop50 & "  c.claimID, VehicleInfo.Marke, VehicleInfo.Modell,b.brandID, m.modelID,b.brand, m.model,c.vehicleID, c.requestedAmount, c.authorizedAmount, c.paymentAmount, c.date, c.paymentDate, pri.priceListDuration, pri.priceListDistance, pri.priceListCategory, pri.price, pri.adminFee,  VehicleInfo.Typ,g.garage, v.regnr, v.vinNumber, p.product,  co.country, co.countryCurrency From tblClaim c FULL JOIN tblGarage g ON g.garageID = c.garageID FULL JOIN tblVehicle v ON v.vehicleID = c.vehicleID  FULL JOIN tblProduct p ON p.productID = v.productID  FULL JOIN tblBrand b ON b.brandID = v.brandID  FULL JOIN tblModel m ON m.modelID = v.modelID  FULL JOIN tblCountry co ON co.countryID = c.countryID  FULL JOIN tblPriceList AS pri ON pri.priceListID = v.priceListID FULL JOIN VehicleInfo ON pri.Typkod = VehicleInfo.Typkod  Where c.claimStatus = " & claimStatus & " Order By c.date Desc")
       
        If RecSet.EOF Then
            Response.Write("<tr><td><font color='red'>No claims found</font></td></tr>")
            
        Else
            Response.Write("<tr bgcolor='#eeeeee'>")
            Response.Write("<td class='formBold'>Country</td>")
            Response.Write("<td class='formBold'>Licence number</td>")
            Response.Write("<td class='formBold'>VIN-number</td>")
            Response.Write("<td class='formBold'>Car make</td>")
            Response.Write("<td class='formBold'>Product</td>")
            Response.Write("<td class='formBold'>Garage</td>")
            Response.Write("<td class='formBold' align='right'>Requested amount</td>")
            Response.Write("<td class='formBold' align='right'>Approved amount</td>")
            Response.Write("<td class='formBold' align='right'>Payment amount</td>")
            Response.Write("<td class='formBold' align='right'>Date</td>")
            Response.Write("<td class='formBold' align='right'>Payment date</td>")
            If Len(subDo) = 0 Then
                Response.Write("<td class='formBold' align='right'></td>")
            End If
            Response.Write("</tr>")
            rowNumber = 1
            Do Until RecSet.EOF
                
                If (RecSet.Fields("brandID").Value = BRANDID1 And RecSet.Fields("modelID").Value = MODELLID1) Then
                    brand = RecSet.Fields("Marke").Value
                    model = RecSet.Fields("Modell").Value
                Else
                    brand = RecSet.Fields("brand").Value
                    model = RecSet.Fields("model").Value
                End If
                claimID = RecSet.Fields("claimID").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                requestedAmount = RecSet.Fields("requestedAmount").Value
                authorizedAmount = RecSet.Fields("authorizedAmount").Value
                paymentAmount = RecSet.Fields("paymentAmount").Value
                __date = RecSet.Fields("date").Value
                paymentDate = RecSet.Fields("paymentDate").Value
                garage = RecSet.Fields("garage").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                product = RecSet.Fields("product").Value
               
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                If rowNumber = 0 Then
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End If
                If IsDBNull(paymentDate) Then
                    paymentDate = "N/A"
                End If
                requestedAmountSum = requestedAmountSum + requestedAmount
                authorizedAmountSum = authorizedAmountSum + authorizedAmount
                paymentAmountSum = paymentAmountSum + paymentAmount
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td>" & brand & " " & model & "</td>")
                Response.Write("<td>" & product & "</td>")
                Response.Write("<td>" & garage & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(requestedAmount), 2) & " " & countryCurrency & "</td>")
                If CInt(claimStatus) = 2 Or CInt(claimStatus) = 3 Then
                    diffAuthorizedAmount = CDbl(requestedAmount) - CDbl(authorizedAmount)
                    If diffAuthorizedAmount > 1 Or CDbl(authorizedAmount) = 0 Then
                        Response.Write("<td align='right' bgcolor='#00CC00'>")
                    ElseIf diffAuthorizedAmount < -1 Then
                        Response.Write("<td align='right' bgcolor='#FF0000'>")
                    Else
                        Response.Write("<td align='right'>")
                    End If
                Else
                    Response.Write("<td align='right'>")
                End If
                Response.Write("" & FormatNumber(CDbl(authorizedAmount), 2) & " " & countryCurrency & "")
                Response.Write("</td>")
                If CInt(claimStatus) = 3 Then
                    diffPaymentAmount = CDbl(authorizedAmount) - CDbl(paymentAmount)
                    If diffPaymentAmount > 1 Then
                        Response.Write("<td align='right' bgcolor='#00CC00'>")
                    ElseIf diffPaymentAmount < -1 Then
                        Response.Write("<td align='right' bgcolor='#FF0000'>")
                    Else
                        Response.Write("<td align='right'>")
                    End If
                Else
                    Response.Write("<td align='right'>")
                End If
                Response.Write("" & FormatNumber(CDbl(paymentAmount), 2) & " " & countryCurrency & "")
                Response.Write("</td>")
                Response.Write("<td align='right'>" & Left(__date, 10) & "</td>")
                Response.Write("<td align='right'>" & Left(paymentDate, 10) & "</td>")
                If Len(subDo) = 0 Then
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End If
                Response.Write("</tr>")
                If flushCounter = 50 Then
                    Response.Flush()
                    flushCounter = 0
                Else
                    flushCounter = flushCounter + 1
                End If
                RecSet.MoveNext()
            Loop
            If rowNumber = 0 Then
                strGrey = " bgcolor='#eeeeee'"
            Else
                strGrey = ""
            End If
            Response.Write("<tr" & strGrey & ">")
            Response.Write("<td colspan='6' class='formBold'>Claim sum:</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(requestedAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(authorizedAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(paymentAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td colspan='3'></td>")
            Response.Write("</tr>")
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='12'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "searchLatest50" Then 
        countryID = Request.QueryString("countryID")
        dateType = Request.QueryString("dateType")
        If Len(countryID) = 0 And Len(dateType) = 0 Then 
            countryID = Request.Form("countryID")
            dateType = Request.Form("dateType")
        End IF
        If Len(dateType) > 0 Then 
            If dateType = CStr(1) Then 
                strDateType = " - BASED ON CLAIM REQUEST MADE DATE"
                strDateTypeHeadline = "Claim request date"
                strSQLOrder = " Order By c.date desc"
            ElseIf dateType = CStr(2) Then 
                strDateType = " - BASED ON CLAIM REQUEST UPDATED DATE"
                strDateTypeHeadline = "Claim request updated date"
                strSQLOrder = " Order By c.updatedByGarageDate desc"
            ElseIf dateType = CStr(3) Then 
                strDateType = " - BASED ON CLAIM DECISION MADE DATE"
                strDateTypeHeadline = "Claim decision made date"
                strSQLOrder = " Order By c.claimDecisionDate desc"
            ElseIf dateType = CStr(4) Then 
                strDateType = " - BASED ON CLAIM DECISION SEND DATE"
                strDateTypeHeadline = "Claim decision send date"
                strSQLOrder = " Order By c.claimDecisionSendDate desc"
            ElseIf dateType = CStr(5) Then 
                strDateType = " - BASED ON CLAIM PAYMENT DATE"
                strDateTypeHeadline = "Claim payment date"
                strSQLOrder = " Order By c.paymentDate desc"
            End IF
        End IF
        If subDo = "print" Then 
            tableWidth = "100%"
            OverPrint()
        ElseIf subDo = "" Then 
            strSQL = " Where c.claimID = 0"
            tableWidth = "100%"
            Over()
        Else
            tableWidth = "100%"
            Over()
        End IF
        strJS = ""
        strJS = strJS + "[""countryID"", ""<1""],"
        strJS = strJS + "[""dateType"", ""<1""],"
        strJS = Left(strJS, Len(strJS) - 1)
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='" & tableWidth & "'>")
        If subDo <> "print" Then 
            Response.Write("<tr>")
            Response.Write("<td valign='top'>")
            Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
            Response.Write("<tr><td class='headline' colspan='3'>SEARCH CLAIM - LATEST 50 BASED ON DATES<hr class='hrHeadline'></td></tr>")
            Response.Write("<form action='searchClaim.aspx?do=searchLatest50&subDo=search' method='post' onsubmit=""javascript:return checkFields();"">")
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Country:</td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='countryID' id='countryID'>")
            Response.Write("<option value=''> Select country  ")
            dbOpen()
            RecSet = Conn.Execute("Select countryID, country From tblCountry")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    dbCountryID = RecSet.Fields("countryID").Value
                    country = RecSet.Fields("country").Value
                    Response.Write("<option value='" & dbCountryID & "'> " & country & " ")
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            Response.Write("<option value=''> -------------------------------------- ")
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td><div id='error_countryID' class='edit_error'>&laquo; OBS!</div></td>")
            Response.Write("</tr>")
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Base result on date type:</td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='dateType' id='dateType'>")
            Response.Write("<option value=''> Select date type ")
            Response.Write("<option value='1'> Claim request made date ")
            Response.Write("<option value='2'> Claim request updated date ")
            Response.Write("<option value='3'> Claim decision made date ")
            Response.Write("<option value='4'> Claim decision send date ")
            Response.Write("<option value='5'> Claim payment date ")
            Response.Write("<option value=''> -------------------------------------- ")
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td><div id='error_dateType' class='edit_error'>&laquo; OBS!</div></td>")
            Response.Write("</tr>")
            Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
            Response.Write("</form>")
            Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
            Response.Write("</table>")
            Response.Write("</td>")
            Response.Write("</tr>")
            Response.Write("<tr><td><br></td></tr>")
        End IF
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='" & tableWidth & "'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='12'>")
        Response.Write("SEARCH RESULT" & strDateType & "")
        If subDo <> "print" Then 
            Response.Write("<a href='searchClaim.aspx?do=searchLatest50&subDo=print&countryID=" & countryID & "&dateType=" & dateType & "' target='_blank'><img src='gui/printer.gif' align='right' alt='Printable version' border='0'></a>")
        End IF
        Response.Write("<hr class='hrHeadline'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        dbOpen()
        ' RecSet = Conn.Execute("Select Top 50 c.claimID, c.vehicleID, c.requestedAmount, c.authorizedAmount, c.paymentAmount, c.date, c.paymentDate, c.claimStatus, c.updatedByGarageDate, c.claimDecisionDate, c.claimDecisionSendDate, g.garage, v.regnr, v.vinNumber, p.product, b.brand, m.model, co.country, co.countryCurrency From ((((((tblClaim c INNER JOIN tblGarage g ON g.garageID = c.garageID) INNER JOIN tblVehicle v ON v.vehicleID = c.vehicleID) INNER JOIN tblProduct p ON p.productID = v.productID) INNER JOIN tblBrand b ON b.brandID = v.brandID) INNER JOIN tblModel m ON m.modelID = v.modelID) INNER JOIN tblCountry co ON co.countryID = c.countryID) " & strSQL & strSQLOrder & "")
       
        RecSet = Conn.Execute("Select Top 50 c.claimID, c.vehicleID, m.brandID, m.modelID, b.brand, m.model,VehicleInfo.Marke, VehicleInfo.Modell, c.requestedAmount, c.authorizedAmount, c.paymentAmount, c.date, c.paymentDate, c.claimStatus, c.updatedByGarageDate,pri.priceListDuration, pri.priceListDistance, pri.priceListCategory, pri.price, pri.adminFee,  VehicleInfo.Typ, c.claimDecisionDate, c.claimDecisionSendDate, g.garage, v.regnr, v.vinNumber, p.product,  co.country, co.countryCurrency From (((((((tblClaim c Full JOIN tblGarage g ON g.garageID = c.garageID) Full JOIN tblVehicle v ON v.vehicleID = c.vehicleID) Full JOIN tblProduct p ON p.productID = v.productID)Full JOIN tblBrand b ON b.brandID = v.brandID)Full JOIN tblModel m ON m.modelID = v.modelID)Full JOIN tblCountry co ON co.countryID = c.countryID)Full JOIN tblPriceList AS pri ON pri.priceListID = v.priceListID)Full JOIN VehicleInfo ON pri.Typkod = VehicleInfo.Typkod " & strSQL & strSQLOrder & "")
        If RecSet.EOF Then
            Response.Write("<tr><td><font color='red'>No claims found</font></td></tr>")
        Else
            Response.Write("<tr bgcolor='#eeeeee'>")
            Response.Write("<td class='formBold'>Country</td>")
            Response.Write("<td class='formBold'>Licence number</td>")
            Response.Write("<td class='formBold'>VIN-number</td>")
            Response.Write("<td class='formBold'>Car make</td>")
            Response.Write("<td class='formBold'>Product</td>")
            Response.Write("<td class='formBold'>Garage</td>")
            Response.Write("<td class='formBold'>Claim status</td>")
            Response.Write("<td class='formBold' align='right'>Requested amount</td>")
            Response.Write("<td class='formBold' align='right'>Approved amount</td>")
            Response.Write("<td class='formBold' align='right'>Payment amount</td>")
            Response.Write("<td class='formBold' align='right'>" & strDateTypeHeadline & "</td>")
            If subDo <> "print" Then
                Response.Write("<td class='formBold' align='right'></td>")
            End If
            Response.Write("</tr>")
            rowNumber = 1
            '****************************************************************
            '****************************************************************
           
            '****************************************************************
            '****************************************************************
            Do Until RecSet.EOF
                
                '**************************************
                If (RecSet.Fields("brandID").Value = BRANDID1 And RecSet.Fields("modelID").Value = MODELLID1) Then
                    brand = RecSet.Fields("Marke").Value
                    model = RecSet.Fields("Modell").Value
                Else
                    brand = RecSet.Fields("brand").Value
                    model = RecSet.Fields("model").Value
                End If
                '**************************************
                
                claimID = RecSet.Fields("claimID").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                requestedAmount = RecSet.Fields("requestedAmount").Value
                authorizedAmount = RecSet.Fields("authorizedAmount").Value
                paymentAmount = RecSet.Fields("paymentAmount").Value
                __date = RecSet.Fields("date").Value
                paymentDate = RecSet.Fields("paymentDate").Value
                claimStatus = RecSet.Fields("claimStatus").Value
                updatedByGarageDate = RecSet.Fields("updatedByGarageDate").Value
                claimDecisionDate = RecSet.Fields("claimDecisionDate").Value
                claimDecisionSendDate = RecSet.Fields("claimDecisionSendDate").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                garage = RecSet.Fields("garage").Value
                product = RecSet.Fields("product").Value
                
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                If rowNumber = 0 Then
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End If
                If CInt(claimStatus) = 0 Then
                    strClaimStatus = "<font color='red'>Not processed</font>"
                ElseIf CInt(claimStatus) = 1 Then
                    strClaimStatus = "<font color='orange'>Under processing</font>"
                ElseIf CInt(claimStatus) = 2 Then
                    strClaimStatus = "<font color='blue'>Processed</font>"
                ElseIf CInt(claimStatus) = 3 Then
                    strClaimStatus = "<font color='green'>Settled</font>"
                End If
                If IsDBNull(updatedByGarageDate) Then
                    updatedByGarageDate = "N/A"
                End If
                If IsDBNull(claimDecisionDate) Then
                    claimDecisionDate = "N/A"
                End If
                If IsDBNull(claimDecisionSendDate) Then
                    claimDecisionSendDate = "N/A"
                End If
                If IsDBNull(paymentDate) Then
                    paymentDate = "N/A"
                End If
                If dateType = CStr(1) Then
                    __date = __date
                ElseIf dateType = CStr(2) Then
                    __date = updatedByGarageDate
                ElseIf dateType = CStr(3) Then
                    __date = claimDecisionDate
                ElseIf dateType = CStr(4) Then
                    __date = claimDecisionSendDate
                ElseIf dateType = CStr(5) Then
                    __date = paymentDate
                End If
                requestedAmountSum = requestedAmountSum + requestedAmount
                authorizedAmountSum = authorizedAmountSum + authorizedAmount
                paymentAmountSum = paymentAmountSum + paymentAmount
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td>" & brand & " " & model & "</td>")
                Response.Write("<td>" & product & "</td>")
                Response.Write("<td>" & garage & "</td>")
                Response.Write("<td>" & strClaimStatus & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(requestedAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(authorizedAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(paymentAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & Left(__date, 10) & "</td>")
                If subDo <> "print" Then
                    Response.Write("<td align='right'><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                End If
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
            If rowNumber = 0 Then
                strGrey = " bgcolor='#eeeeee'"
            Else
                strGrey = ""
            End If
            Response.Write("<tr" & strGrey & ">")
            Response.Write("<td colspan='7' class='formBold'>Claim sum:</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(requestedAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(authorizedAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(paymentAmountSum), 2) & " " & countryCurrency & "</td>")
            Response.Write("<td colspan='3'></td>")
            Response.Write("</tr>")
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='12'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "byClaimIDForm" Then 
        Over()
        strJS = ""
        strJS = strJS + "[""claimID"", ""==''""],"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>SEARCH CLAIM - BY CLAIM ID<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='searchClaim.aspx?do=byClaimIDSearch' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Claim ID:</td>")
        Response.Write("<td align='right'><input type='text' name='claimID' id='claimID' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td>")
        Response.Write("<td><div id='error_claimID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "byClaimIDSearch" Then 
        claimID = Request.Form("claimID")
        If Len(claimID) = 0 Then 
            Response.Redirect("searchClaim.aspx?do=byClaimIDForm&subDo=%20-%20NO%20CLAIM%20FOUND")
        Else
            claimID = CLng(claimID)
        End IF
        dbOpen()
        RecSet = Conn.Execute("Select vehicleID From tblClaim Where claimID = " & claimID & "")
        If RecSet.EOF Then 
            vehicleID = 0
        Else
            vehicleID = RecSet.Fields("vehicleID").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If CInt(vehicleID) = 0 Then 
            Response.Redirect("searchClaim.aspx?do=byClaimIDForm&subDo=%20-%20NO%20CLAIM%20FOUND")
        Else
            Response.Redirect("editVehicle.aspx?vehicleID=" & vehicleID & "")
        End IF
    ElseIf Request.QueryString("do") = "byGarageInvoiceIDForm" Then 
        Over()
        strJS = ""
        strJS = strJS + "[""garageInvoiceID"", ""==''""],"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>SEARCH CLAIM - BY GARAGES INVOICE ID<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='searchClaim.aspx?do=byGarageInvoiceIDSearch' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Garages invoice ID:</td>")
        Response.Write("<td align='right'><input type='text' name='garageInvoiceID' id='garageInvoiceID' size='40' maxlength='50'></td>")
        Response.Write("<td><div id='error_garageInvoiceID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "byGarageInvoiceIDSearch" Then 
        garageInvoiceID = Request.Form("garageInvoiceID")
        If Len(garageInvoiceID) = 0 Then 
            Response.Redirect("searchClaim.aspx?do=byGarageInvoiceIDForm&subDo=%20-%20NO%20CLAIM%20FOUND")
        End IF
        dbOpen()
        RecSet = Conn.Execute("Select vehicleID From tblClaim Where garageInvoiceID = '" & garageInvoiceID & "'")
        If RecSet.EOF Then 
            vehicleID = 0
        Else
            vehicleID = RecSet.Fields("vehicleID").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If CInt(vehicleID) = 0 Then 
            Response.Redirect("searchClaim.aspx?do=byGarageInvoiceIDForm&subDo=%20-%20NO%20CLAIM%20FOUND")
        Else
            Response.Redirect("editVehicle.aspx?vehicleID=" & vehicleID & "")
        End IF
    ElseIf Request.QueryString("do") = "dateClaimSum" Then 
        If subDo = "print" Then 
            tableWidth = "100%"
            OverPrint()
        ElseIf subDo = "" Then 
            strSQL = " Where c.claimID = 0"
            tableWidth = "100%"
            Over()
        Else
            tableWidth = "100%"
            Over()
        End IF
        strJS = ""
        strJS = strJS + "[""countryID"", ""<1""],"
        strJS = strJS + "[""partnerID"", ""<1""]"
        checkFields()
        dbOpen()
        RecSet = Conn.Execute("Select partnerID, partnerName, countryID From tblPartner Order by partnerName")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                partnerID = RecSet.Fields("partnerID").Value
                partnerName = RecSet.Fields("partnerName").Value
                countryID = RecSet.Fields("countryID").Value
                strSelectSubJS = strSelectSubJS + "new Array(" & partnerID & "," & countryID & ",""" & partnerName & """),"
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("Select countryID From tblCountry Order by countryID")
        Do Until RecSet.EOF
            countryID = RecSet.Fields("countryID").Value
            strSelectSubJS = strSelectSubJS + "new Array(0," & countryID & ","" ------------------------------------  ""),"
            RecSet.MoveNext()
        Loop
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        strSelectSubJS = Left(strSelectSubJS, Len(strSelectSubJS) - 1)
        strSelectSubHeadline = "Select partner"
        selectSub()
        countryID = Request.QueryString("countryID")
        partnerID = Request.QueryString("partnerID")
        If Len(countryID) = 0 And Len(partnerID) = 0 Then 
            countryID = Request.Form("countryID")
            partnerID = Request.Form("partnerID")
        End IF
        countryID = CLng(countryID)
        partnerID = CLng(partnerID)
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='" & tableWidth & "'>")
        If subDo <> "print" Then 
            Response.Write("<tr>")
            Response.Write("<td valign='top'>")
            Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
            Response.Write("<tr><td class='headline' colspan='3'>SEARCH CLAIM SUM BY DATE<hr class='hrHeadline'></td></tr>")
            Response.Write("<form action='searchClaim.aspx?do=dateClaimSum&subDo=search' method='post' name='store_productsSearch' onsubmit=""javascript:return checkFields();"">")
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Country:</td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='countryID' id='countryID' onchange=""set_child_listbox(this, document.store_productsSearch.partnerID,Product,'Products');"">")
            Response.Write("<option value=''> Select country  ")
            dbOpen()
            RecSet = Conn.Execute("Select countryID, country From tblCountry Order By country")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    countryID = RecSet.Fields("countryID").Value
                    country = RecSet.Fields("country").Value
                    Response.Write("<option value='" & countryID & "'> " & country & " ")
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            Response.Write("<option value=''> -------------------------------------- ")
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td><div id='error_countryID' class='edit_error'>&laquo; OBS!</div></td>")
            Response.Write("</tr>")
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Partner:</td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='partnerID' id='partnerID' disabled>")
            Response.Write("<option value=''> Select partner ")
            Response.Write("<option value=''> -------------------------------------- ")
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td><div id='error_partnerID' class='edit_error'>&laquo; OBS!</div></td>")
            Response.Write("</tr>")
            Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
            Response.Write("</form>")
            Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
            Response.Write("</table>")
            Response.Write("</td>")
            Response.Write("</tr>")
            Response.Write("<tr><td><br></td></tr>")
        End IF
        If Len(subDo) > 0 Then 
            dbOpen()
            RecSet = Conn.Execute("Select p.partnerName, co.countryCurrency, co.decimals From (tblPartner p INNER JOIN tblCountry co ON co.countryID = p.countryID) Where p.partnerID = " & partnerID & "")
            partnerName = RecSet.Fields("partnerName").Value
            countryCurrency = RecSet.Fields("countryCurrency").Value
            decimals = RecSet.Fields("decimals").Value
            RecSet.Close()
            RecSet = Nothing
            dbClose()
        End IF
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='" & tableWidth & "'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='5'>")
        Response.Write("SEARCH RESULT FOR " & UCase(partnerName) & "")
        If subDo <> "print" Then 
            Response.Write("<a href='searchClaim.aspx?do=dateClaimSum&subDo=print&countryID=" & countryID & "&partnerID=" & partnerID & "' target='_blank'><img src='gui/printer.gif' align='right' alt='Printable version' border='0'></a>")
        End IF
        Response.Write("<hr class='hrHeadline'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        __date = ""
        claimCount = 0
        dbOpen()
        RecSet = Conn.Execute("Select CAST(FLOOR(CAST(c.date AS FLOAT)) AS DATETIME) As date, Count(c.claimID) As claimCount, Sum(c.requestedAmount) As requestedAmountSum, Sum(c.authorizedAmount) As authorizedAmountSum, Sum(c.paymentAmount) As paymentAmountSum From (tblClaim c INNER JOIN tblVehicle v ON v.vehicleID = c.vehicleID) Where v.partnerID = " & partnerID & " Group By CAST(FLOOR(CAST(c.date AS FLOAT)) AS DATETIME) Order By CAST(FLOOR(CAST(c.date AS FLOAT)) AS DATETIME) Desc")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>No claims found</font></td></tr>")
        Else
            Response.Write("<tr bgcolor='#eeeeee'>")
            Response.Write("<td class='formBold'>Claim date</td>")
            Response.Write("<td class='formBold' align='right'>Number of claims</td>")
            Response.Write("<td class='formBold' align='right'>Requested amount</td>")
            Response.Write("<td class='formBold' align='right'>Approved amount</td>")
            Response.Write("<td class='formBold' align='right'>Payment amount</td>")
            Response.Write("</tr>")
            rowNumber = 1
            Do Until RecSet.EOF
                __date = RecSet.Fields("date").Value
                claimCount = RecSet.Fields("claimCount").Value
                requestedAmountSum = RecSet.Fields("requestedAmountSum").Value
                authorizedAmountSum = RecSet.Fields("authorizedAmountSum").Value
                paymentAmountSum = RecSet.Fields("paymentAmountSum").Value
                paymentAmountSum = FormatNumber(CDbl(paymentAmountSum), decimals)
                paymentAmountSum = CDbl(paymentAmountSum)
                requestedAmountSum = FormatNumber(CDbl(requestedAmountSum), decimals)
                requestedAmountSum = CDbl(requestedAmountSum)
                authorizedAmountSum = FormatNumber(CDbl(authorizedAmountSum), decimals)
                authorizedAmountSum = CDbl(authorizedAmountSum)
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & __date & "</td>")
                Response.Write("<td align='right'>" & claimCount & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(requestedAmountSum), decimals) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(authorizedAmountSum), decimals) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(paymentAmountSum), decimals) & " " & countryCurrency & "</td>")
                Response.Write("</tr>")
                requestedAmountTotSum = requestedAmountTotSum + requestedAmountSum
                authorizedAmountTotSum = authorizedAmountTotSum + authorizedAmountSum
                paymentAmountTotSum = paymentAmountTotSum + paymentAmountSum
                claimTotCount = claimTotCount + claimCount
                RecSet.MoveNext()
            Loop
            If rowNumber = 0 Then 
                strGrey = " bgcolor='#eeeeee'"
            Else
                strGrey = ""
            End IF
            Response.Write("<tr" & strGrey & ">")
            Response.Write("<td class='formBold'>Claim sum:</td>")
            Response.Write("<td align='right' class='formBold'>" & claimTotCount & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(requestedAmountTotSum), decimals) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(authorizedAmountTotSum), decimals) & " " & countryCurrency & "</td>")
            Response.Write("<td align='right' class='formBold'>" & FormatNumber(CDbl(paymentAmountTotSum), decimals) & " " & countryCurrency & "</td>")
            Response.Write("</tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='5'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    End IF
%>

